PausePanel = class("PausePanel")

function PausePanel.create(parent)
    local panel = PausePanel.new()
    panel:init(parent)

    uiEffect.bounceIn(panel.view)
    parent:base_onOpenWin(panel)

    return panel
end

function PausePanel:init(parent)
    self.view = ccs.GUIReader:getInstance():widgetFromJsonFile("pausePanel.json")
    parent.widget:addChild(self.view)
    self.view:setLocalZOrder(pp.z_pause)
    self.parent = parent

    local function btContinueCallback(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            AudioEngine.playEffect(sound.btn1)
         elseif eventType == ccui.TouchEventType.ended then
             self:close()
             self.parent:game_resume_callback()
         end
    end
    local bt_continue = self.view:getChildByName("_continue")
    bt_continue:addTouchEventListener(btContinueCallback)
    uiEffect.jelly(bt_continue)
    
    local function btToLevelCallback(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            AudioEngine.playEffect(sound.btn1)
        elseif eventType == ccui.TouchEventType.ended then
            uiEffect.bounceOut(self.view, true)

            parent:game_level_callbak()
            parent:base_onCloseWin(self)

        end
    end
    local bt_level = self.view:getChildByName("_to_level")
    bt_level:addTouchEventListener(btToLevelCallback)

    local function btAgCallback(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            AudioEngine.playEffect(sound.btn1)
        elseif eventType == ccui.TouchEventType.ended then
            uiEffect.bounceOut(self.view, true)

            parent:game_playAgain_callbak()
            parent:base_onCloseWin(self)

        end
    end
    local bt_again = self.view:getChildByName("_again")
    bt_again:addTouchEventListener(btAgCallback)
end 
 
function PausePanel:close()
    -- body
    uiEffect.bounceOut(self.view, true)
    self.parent:base_onCloseWin(self)
end